package com.tytc56.user.wxapi;


import org.kymjs.kjframe.KJDB;
import org.kymjs.kjframe.utils.KJLoger;

import net.sourceforge.simcpux.Constants;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.taiyuan.tongcheng.application.TCBroadcastAction;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tytc56.user.R;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);
        
    	api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);

        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		
		KJLoger.debug( "onPayFinish, errCode = " + resp.errCode);
		
		Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);
		if(resp.errCode==-2){
//			Toast.makeText(getApplicationContext(), "支付失败", 1).show();
			sendBroadcast(new Intent(TCBroadcastAction.ERROR_WX_PAY_CANCEL));
			WXPayEntryActivity.this.finish();
		}
		
		if(resp.errCode== BaseResp.ErrCode.ERR_OK){
//			Toast.makeText(getApplicationContext(), "支付失败", 1).show();
			sendBroadcast(new Intent(TCBroadcastAction.SUCCESS_WX_PAY_OK));
			WXPayEntryActivity.this.finish();
		}
		
	}
}